
import { Route, Routes ,Navigate} from "react-router-dom"
import routerArr from "./index"
import Wrapper from "../conmpones/wrapper/Wrapper"
export function createRouter() {
    let arr = routerArr.map((item) => {
        // 重定向
        if (item.redirect) {
            return <Route key={item.path}  path={item.path} element={<Navigate to={item.redirect} replace={true}></Navigate>}></Route>
        }
        if (item.children) {
            return <Route key={item.path} path={item.path} element={ <Wrapper customData={item.customData} Component={item.component}></Wrapper> }>
                {item.children.map((items) => {
                    return <Route key={items.path} path={items.path} eelement={ <Wrapper customData={items.customData} Component={items.component}></Wrapper> }></Route>
                })
                }
            </Route>
        } else {
            return <Route key={item.path} path={item.path}  element={ <Wrapper customData={item.customData} Component={item.component}></Wrapper> }> </Route>
        }


    })
    // 网页错误跳转
    arr.push(<Route key={`404`} path="*" Component={() => <div>404网页错误</div>} />)
    return <Routes> {arr} </Routes>

}